<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>composition API-toRefs reactive</title>
  <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
  <div id="root"></div>
</body>
<script>
  // ref reactive 响应式的引用
	// 原理 通过 proxy 对数据进行封装，当数据变化时，触发模版等内容的更新
	// ref 处理基础类型的数据
	// reactive 处理非基础类型的数据
  const app = Vue.createApp({
    template: `
      <div>name: {{userInfo.name}}</div>
    `,
		setup(props,context) {
			//const {ref} =Vue
			//  proxy 'dell' 变成  proxy({value:'dell'})这样的一个响应式引用
			// let name = ref('dell'); //ref 
			// setTimeout(()=>{
			// 	name.value ='lee'
			// },2000)
			// return {
			// 	name
			// }

		
			const {reactive,readonly, toRefs} = Vue
				//reactive  readonly
			// const userInfo = reactive({name:'dell',age:10})
			// setTimeout(()=>{
			// 	userInfo.name ='lee'
			// },2000)
			// const copyName = readonly(userInfo)
			// setTimeout(()=>{
			// 	userInfo.name ='lee'
			// },2000)
			// return {
			// 	userInfo
			// }

			//toRefs 
			const userInfo = reactive({name:'dell'})
			setTimeout(()=>{
				userInfo.name ='lee'
			},2000)
			// proxy({name:'dell'}) => {name:proxy({value:'dell'})}
			const {name} = toRefs(userInfo)
			return {
				name
			}
		}
  });
  const vm = app.mount('#root');
</script>
</html>